import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout'

Vue.use(VueRouter)
//解决重复点击左侧菜单的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export const asyncRoutes = [
  {
    path: '/',
    name: 'root',
    component: Layout,
    redirect: '/home',
    hidden: true
  },
  {
    path: '/home',
    name: 'home',
    component: Layout,
    meta: {
      title: "首页",
      icon: 'el-icon-s-home'
    },
    children: [{
      path: '',
      component: () => import('@/views/home.vue'),
      meta: {
        title: "首页"
      }
    }]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/login'),
    meta: {
      title: "欢迎登录",
    },
    hidden: true
  },
  {
    path: '/learning-record',
    name: 'LearningRecord',
    component: Layout,
    meta: {
      title: '学习记录',
      icon: 'el-icon-notebook-1'
    },
    children: [{
      path: '',
      component: () => import('@/views/learning/record/index'),
      meta: {
        title: '学习记录'
      }
    }]
  },
  {
    path: '/learning-detail/:id',
    name: 'LearningDetail',
    component: Layout,
    meta: {
      title: '课程详情',
      icon: 'el-icon-document',
      activeMenu: '/learning-record'
    },
    hidden: true,
    children: [{
      path: '',
      component: () => import('@/views/learning/detail'),
      meta: {
        title: '课程详情'
      }
    }]
  },
  {
    path: '/learning-record-detail/:id',
    name: 'LearningRecordDetail',
    component: Layout,
    meta: {
      title: '学习详情',
      icon: 'el-icon-document',
      activeMenu: '/learning-record'
    },
    hidden: true,
    children: [{
      path: '',
      component: () => import('@/views/learning/record/detail'),
      meta: {
        title: '学习详情'
      }
    }]
  },
  {
    path: '/chat',
    name: 'ChatIndex',
    component: Layout,
    meta: {
      title: '聊天',
      icon: 'el-icon-chat-line-round'
    },
    children: [{
      path: '',
      component: () => import('@/views/chat/index'),
      meta: {
        title: '在线交流'
      }
    }]
  },
  {
    path: '/knowledge-node',
    name: 'KnowledgeNode',
    component: Layout,
    meta: {
      title: '知识点列表',
      icon: 'el-icon-connection'
    },
    children: [{
      path: '',
      component: () => import('@/views/knowledge/node/index'),
      meta: {
        title: '知识点列表'
      }
    }]
  },
  {
    path: '/knowledge-relation',
    name: 'KnowledgeRelation',
    component: Layout,
    meta: {
      title: '知识关系管理',
      icon: 'el-icon-share'
    },
    children: [{
      path: '',
      component: () => import('@/views/knowledge/relation/index'),
      meta: {
        title: '知识关系管理'
      }
    }]
  },
  {
    path: '/learning-resource',
    name: 'LearningResource',
    component: Layout,
    meta: {
      title: '学习资源管理',
      icon: 'el-icon-document'
    },
    children: [{
      path: '',
      component: () => import('@/views/knowledge/resource/index'),
      meta: {
        title: '学习资源管理'
      }
    }]
  },
  {
    path: '/learning-path',
    name: 'LearningPath',
    component: Layout,
    meta: {
      title: '学习路径管理',
      icon: 'el-icon-guide'
    },
    children: [{
      path: '',
      component: () => import('@/views/knowledge/path/index'),
      meta: {
        title: '学习路径管理'
      }
    },
    {
      path: 'node-relation/:pathId',
      name: 'PathNodeRelation',
      component: () => import('@/views/knowledge/path/node'),
      meta: {
        title: '路径节点关联',
        activeMenu: '/learning-path'
      },
      hidden: true
    }]
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: asyncRoutes
})

export default router
